Section 38. Any person who knowingly violates any provision of subsection (a) of section twenty-four, or of section twenty-five, twenty-six or twenty-seven shall be punished by imprisonment for not more than one year or by a fine of not more than one thousand dollars, or both. Whoever violates any of the provisions of any of said sections after one or more prior convictions of a violation of any provision of this chapter or of a provision of prior law relating to the sale or manufacture of narcotic drugs or harmful drugs as defined in said prior law shall be punished by imprisonment for not more than two years or by a fine of not more than two thousand dollars, or both.